package com.woniuxy.oldmanapi.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.oldmanapi.entity.Discharge;
import com.woniuxy.oldmanapi.service.CheckInService;
import com.woniuxy.oldmanapi.service.DischargeService;
import com.woniuxy.oldmanapi.vo.ResponseResult;
import com.woniuxy.oldmanapi.xvo.OlderVo;
import com.woniuxy.oldmanapi.zvo.CheckInVo;
import com.woniuxy.oldmanapi.zvo.DischargeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
public class CheckInController {
    @Autowired
    CheckInService checkInService;

    @GetMapping("/checkIn/selectRoomPayById/{id}")
    public ResponseResult<OlderVo> selectRoomPayById(@PathVariable(value = "id")int id){
        ResponseResult<OlderVo> result = new ResponseResult<>();
        try {
            OlderVo pageInfo = checkInService.selectRoomPayById(id);
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }

    @GetMapping("/checkIn/selectCarePayById/{id}")
    public ResponseResult<OlderVo> selectCarePayById(@PathVariable(value = "id")int id){
        ResponseResult<OlderVo> result = new ResponseResult<>();
        try {
            OlderVo pageInfo = checkInService.selectCarePayById(id);
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }
    @GetMapping("/checkIn/selectCheckInById/{id}")
    public ResponseResult<CheckInVo> selectCheckInById(@PathVariable(value = "id")int id){
        ResponseResult<CheckInVo> result = new ResponseResult<>();
        try {
            CheckInVo pageInfo = checkInService.selectCheckInById(id);
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }


    //查询咨询者信息
    @GetMapping("/checkIn/selectCheckIn")
    public ResponseResult<PageInfo<CheckInVo>> selectCheckIn(int now, int size, String name,
                                                             Date beginDate,
                                                             Date endDate,
                                                              @RequestParam(value = "status",defaultValue = "-1") int status){
        ResponseResult<PageInfo<CheckInVo>> result = new ResponseResult<>();
        try {
            PageInfo<CheckInVo> pageInfo = checkInService.selectCheckIn(now, size, name,beginDate,endDate,status);
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }
    //作废
    @GetMapping("/checkIn/cancelCheckIn/{id}")
    public ResponseResult<Void> cancelCheckIn(@PathVariable(value = "id") int id){
        ResponseResult<Void> result = new ResponseResult<>();
        try {
            checkInService.cancelCheckIn(id);
            result.setCode(200);
            result.setMsg("作废成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }

    //新增咨询者信息
    @PostMapping("/checkIn/insertCheckIn")
    public ResponseResult<Void> insertCheckIn(@RequestBody CheckInVo consulter){
        ResponseResult<Void> result = new ResponseResult<>();
        try {
            checkInService.insertCheckIn(consulter);
            result.setCode(200);
            result.setMsg("添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg(e.getMessage());
        }
        return result;
    }
}
